package com.group.patients.service.impl;

import com.group.commons.entity.patient.Receiver;
import com.group.patients.dao.ReceiverDao;
import com.group.service.ReceiverService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Receiver)表服务实现类
 *
 * @author makejava
 * @since 2022-06-07 11:12:28
 */
@Service("receiverService")
public class ReceiverServiceImpl implements ReceiverService {
    @Resource
    private ReceiverDao receiverDao;

    /**
     * 通过ID查询单条数据
     *
     * @param receiverid 主键
     * @return 实例对象
     */
    @Override
    public Receiver queryById(Integer receiverid) {
        return this.receiverDao.queryById(receiverid);
    }

    /**
     * 分页查询
     *
     * @param receiver 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Receiver> queryByPage(Receiver receiver, PageRequest pageRequest) {
        long total = this.receiverDao.count(receiver);
        return new PageImpl<>(this.receiverDao.queryAllByLimit(receiver, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param receiver 实例对象
     * @return 实例对象
     */
    @Override
    public Receiver insert(Receiver receiver) {
        this.receiverDao.insert(receiver);
        return receiver;
    }

    /**
     * 修改数据
     *
     * @param receiver 实例对象
     * @return 实例对象
     */
    @Override
    public Receiver update(Receiver receiver) {
        this.receiverDao.update(receiver);
        return this.queryById(receiver.getReceiverid());
    }

    /**
     * 通过主键删除数据
     *
     * @param receiverid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer receiverid) {
        return this.receiverDao.deleteById(receiverid) > 0;
    }
}
